import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../common/common_config.dart';
import '../assets/color_config.dart';
import 'common_page_config.dart';

class ThemeUtil {
  static SystemUiOverlayStyle systemOverlayStyleLight =
      const SystemUiOverlayStyle(
    statusBarColor: Colors.transparent,
    statusBarBrightness: Brightness.light,
    statusBarIconBrightness: Brightness.dark,
    systemNavigationBarIconBrightness: Brightness.dark,
    systemNavigationBarColor: Colors.transparent,
    systemNavigationBarDividerColor: Colors.transparent,
  );
  static SystemUiOverlayStyle systemOverlayStyleDark =
      const SystemUiOverlayStyle(
    statusBarColor: Colors.transparent,
    statusBarBrightness: Brightness.light,
    statusBarIconBrightness: Brightness.light,
    systemNavigationBarIconBrightness: Brightness.light,
    systemNavigationBarColor: Colors.transparent,
    systemNavigationBarDividerColor: Colors.transparent,
  );

  static const SystemUiOverlayStyle dark = SystemUiOverlayStyle(
    statusBarColor: Colors.transparent,
    systemNavigationBarColor: Color(0xFFffffff),
    systemNavigationBarIconBrightness: Brightness.light,
    statusBarIconBrightness: Brightness.dark,
    statusBarBrightness: Brightness.light,
    systemNavigationBarDividerColor: Colors.transparent,
  );

  static const SystemUiOverlayStyle light = SystemUiOverlayStyle(
    statusBarColor: Colors.transparent,
    systemNavigationBarColor: Color(0xFFffffff),
    systemNavigationBarIconBrightness: Brightness.light,
    statusBarIconBrightness: Brightness.light,
    statusBarBrightness: Brightness.dark,
    systemNavigationBarDividerColor: Colors.transparent,
  );

  static ThemeMode getDeviceThemeMode() {
    return ThemeMode.light;
  }

  static ThemeData obtainThemeData(bool light) {
    if (light) {
      return ThemeData.light().copyWith(
        primaryColor: Colors.white,
        primaryColorLight: Colors.white,
        primaryColorDark: Colors.white,
        canvasColor: Colors.grey[100],
        scaffoldBackgroundColor: Colors.white,
        bottomAppBarTheme: const BottomAppBarTheme(color: Colors.white),
        cardColor: Colors.white,
        splashColor: Colors.white,
        highlightColor: Colors.transparent,
        dividerColor: ColorConfig.colorCCC,
        indicatorColor: ColorConfig.colorPrimary,
        appBarTheme: commonPageConfig.appBarLightTheme(),
        bottomNavigationBarTheme: BottomNavigationBarThemeData(
          backgroundColor: Colors.white,
          unselectedItemColor: const Color(0xff666666),
          unselectedLabelStyle: TextStyle(fontSize: 10.sp),
          unselectedIconTheme: IconThemeData(
            color: const Color(0xff666666),
            size: 25.w,
          ),
          selectedItemColor: ColorConfig.colorPrimary,
          selectedLabelStyle: TextStyle(fontSize: 10.sp),
          selectedIconTheme: IconThemeData(
            color: ColorConfig.colorPrimary,
            size: 25.w,
          ),
        ),
        textTheme: TextTheme(
          headlineLarge: TextStyle(
            color: ColorConfig.colorBlack,
            fontFamily: CommonConfig.configFont,
          ),
          titleSmall: TextStyle(
            color: ColorConfig.colorBlack,
            fontFamily:CommonConfig.configFont,
          ),
          bodyLarge: TextStyle(
            color: ColorConfig.colorBlack,
            fontFamily:CommonConfig.configFont,
          ),
          bodyMedium: TextStyle(
            color: ColorConfig.colorBlack,
            fontFamily:CommonConfig.configFont,
          ),
          bodySmall: TextStyle(
            color: ColorConfig.colorBlack,
            fontFamily:CommonConfig.configFont,
          ),
        ),
        textSelectionTheme: TextSelectionThemeData(
          cursorColor: ColorConfig.colorPrimary,
          selectionColor: ColorConfig.colorPrimary.withAlpha(100),
          selectionHandleColor: ColorConfig.colorPrimary,
        ),
        buttonTheme: ButtonThemeData(
          buttonColor: ColorConfig.colorPrimary,
        ),
        iconTheme: IconThemeData(
          color: ColorConfig.colorBlack,
        ),
        primaryIconTheme: IconThemeData(
          color: ColorConfig.colorBlack,
        ),
        cupertinoOverrideTheme: NoDefaultCupertinoThemeData(
          primaryColor: ColorConfig.colorBlack,
        ),
        dialogTheme: DialogTheme(
          titleTextStyle: TextStyle(
            color: ColorConfig.colorBlack,
            fontSize: 18.sp,
          ),
          contentTextStyle: TextStyle(
            color: ColorConfig.colorBlack,
            fontSize: 16.sp,
          ),
        ),
        colorScheme: ColorScheme(
          primary: Colors.white,
          primaryContainer: Colors.white,
          secondary: ColorConfig.colorPrimary,
          secondaryContainer: ColorConfig.colorPrimary,
          background: Colors.white,
          surface: Colors.white,
          brightness: Brightness.light,
          error: const Color(0xffcf6679),
          onPrimary: Colors.white,
          onSecondary: Colors.white,
          onSurface: Colors.black,
          onBackground: Colors.black,
          onError: Colors.white,
        ),
      );
    } else {
      return ThemeData.dark().copyWith(
        primaryColor: Colors.grey[900],
        primaryColorLight: Colors.grey[900],
        primaryColorDark: Colors.grey[900],
        canvasColor: Colors.grey[850],
        scaffoldBackgroundColor: Colors.grey[900],
        bottomAppBarTheme: BottomAppBarTheme(color: Colors.grey[900]),
        cardColor: Colors.grey[900],
        highlightColor: Colors.transparent,
        dividerColor: const Color(0xff666666),
        splashColor: Colors.grey[900],
        indicatorColor: ColorConfig.colorPrimary,
        appBarTheme: commonPageConfig.appBarDarkTheme(),
        bottomNavigationBarTheme: BottomNavigationBarThemeData(
          backgroundColor: Colors.grey[900],
          unselectedItemColor: const Color(0xffAAAAAA),
          unselectedLabelStyle: TextStyle(fontSize: 10.sp),
          unselectedIconTheme: IconThemeData(
            color: const Color(0xffAAAAAA),
            size: 25.w,
          ),
          selectedItemColor: ColorConfig.colorPrimary,
          selectedLabelStyle: TextStyle(fontSize: 10.sp),
          selectedIconTheme: IconThemeData(
            color: ColorConfig.colorPrimary,
            size: 25.w,
          ),
        ),
        textTheme: TextTheme(
          headlineLarge: TextStyle(
            color: ColorConfig.colorCCC,
            fontFamily: CommonConfig.configFont,
          ),
          titleSmall: TextStyle(
            color: ColorConfig.colorCCC,
            fontFamily: CommonConfig.configFont,
          ),
          bodyLarge: TextStyle(
            color: ColorConfig.colorCCC,
            fontFamily: CommonConfig.configFont,
          ),
          bodyMedium: TextStyle(
            color: ColorConfig.colorCCC,
            fontFamily: CommonConfig.configFont,
          ),
          bodySmall: TextStyle(
            color: ColorConfig.colorCCC,
            fontFamily: CommonConfig.configFont,
          ),
        ),
        textSelectionTheme: TextSelectionThemeData(
          cursorColor: ColorConfig.colorPrimary,
          selectionColor: ColorConfig.colorPrimary.withAlpha(100),
          selectionHandleColor: ColorConfig.colorPrimary,
        ),
        buttonTheme: ButtonThemeData(buttonColor: ColorConfig.colorPrimary),
        iconTheme: const IconThemeData(
          color: Color(0xffAAAAAA),
        ),
        primaryIconTheme: const IconThemeData(
          color: Color(0xffAAAAAA),
        ),
        cupertinoOverrideTheme: const NoDefaultCupertinoThemeData(
          primaryColor: Color(0xffAAAAAA),
        ),
        dialogTheme: DialogTheme(
          titleTextStyle: TextStyle(
            color: const Color(0xffAAAAAA),
            fontSize: 18.sp,
          ),
          contentTextStyle: TextStyle(
            color: const Color(0xffAAAAAA),
            fontSize: 16.sp,
          ),
        ),
        colorScheme: ColorScheme(
          primary: Colors.grey[900] ?? const Color(0xFF212121),
          primaryContainer: Colors.grey[900] ?? const Color(0xFF212121),
          secondary: ColorConfig.colorPrimary,
          secondaryContainer: ColorConfig.colorPrimary,
          background: Colors.grey[900] ?? const Color(0xFF212121),
          surface: Colors.grey[900] ?? const Color(0xFF212121),
          brightness: Brightness.dark,
          error: const Color(0xffcf6679),
          onPrimary: Colors.black,
          onSecondary: Colors.black,
          onSurface: Colors.white,
          onBackground: Colors.white,
          onError: Colors.black,
        ),
      );
    }
  }
}
